package ciyuan;

import ciyuan.wrap.Wrapper;

import java.net.URL;

/**
 * @author 150149
 */
public class Updater {

    private static long updateTime = 0;

    public static void checkUpdate() {
        if (System.currentTimeMillis() - updateTime < 60 * 60 * 1000) {
            return;
        }
        if (!QQLogin.config.CheckLinkUpdate) {
            return;
        }
        updateTime = System.currentTimeMillis();
        try {
            URL url = new URL(QQLogin.config.CheckLoginURL + "/MCloginUpdate?server=" + QQLogin.config.ServerName);
            String response = Utils.getHttp(url);
            if (!response.isEmpty() && !response.equals(QQLogin.config.CheckLoginURL)) {
                Object config = Wrapper.INSTANCE.loadConfig();
                Wrapper.INSTANCE.configSetValue(config, "CheckLoginURL", response);
                Wrapper.INSTANCE.saveConfig(config);
                Wrapper.INSTANCE.logMsg(QQLogin.PREFIX + "QQ机器人服务器链接已自动更新!");
            }
        } catch (Exception ignored) {
        }
    }

}
